home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / inet / internet-drafts / draft-ietf-avt-video-packet-00.txt < prev    next >
Text File  |  1993-03-21  |  29KB  |  896 lines

  1.  
  2.  
  3.  
  4.           Internet draft                     Packetization of H.261
  5.  
  6.  
  7.                                   Packetization
  8.                                        of
  9.                                H.261 video streams
  10.  
  11.  
  12.  
  13.                                  Mon Mar 8, 1993
  14.                              Expires:  October 1993
  15.  
  16.  
  17.                        Thierry Turletti, Christian Huitema
  18.                                       INRIA
  19.  
  20.                         Christian.Huitema@sophia.inria.fr
  21.                          Thierry.Turletti@sophia.inria.fr
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.           1.  Status of this Memo
  29.  
  30.           This document is an Internet draft. Internet drafts are
  31.           working documents of the Internet Engineering Task Force
  32.           (IETF), its Areas, and its Working Groups. Note that other
  33.           groups may also distribute working documents as Internet
  34.           Drafts).
  35.  
  36.           Internet Drafts are draft documents valid for a maximum of six
  37.           months. Internet Drafts may be updated, replaced, or obsoleted
  38.           by other documents at any time. It is not appropriate to use
  39.           Internet Drafts as reference material or to cite them other
  40.           than as a "working draft" or "work in progress".
  41.  
  42.           Please check the I-D abstract listing contained in each
  43.           Internet Draft directory to learn the current status of this
  44.           or any other Internet Draft.
  45.  
  46.           Distribution of this document is unlimited.
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.           Turletti, Huitema                                     [Page 1]
  60.  
  61.  
  62.  
  63.  
  64.  
  65.           Internet draft                     Packetization of H.261
  66.  
  67.  
  68.           2.  Purpose of this document
  69.  
  70.           The CCITT recommendation H.261 [1] specifies the encodings
  71.           used by CCITT compliant video-conference codecs. Although
  72.           these encodings were originally specified for fixed data rate
  73.           ISDN circuits, experimentations [2]  have shown that they can
  74.           also be used over the internet.
  75.  
  76.           The purpose of this memo is to specify how H.261 video streams
  77.           can be carried over UDP and IP, using the RTP protocol [3].
  78.  
  79.  
  80.           3.  Structure of the packet stream
  81.  
  82.           H.261 codecs produce a bit stream. In fact, H.261 and
  83.           companion recommendations specifies several levels of
  84.           encoding:
  85.  
  86.           (1)  Images are first separated in blocks of 8x8 pixels.
  87.                Blocks which have moved are encoded by computing the
  88.                discrete cosine transform (DCT) of their coefficients,
  89.                which are then quantized and Huffman encoded.
  90.  
  91.           (2)  The bits resulting of the Huffman encoding are then
  92.                arranged in 512 bits frames, containing 2 bits of
  93.                synchronization, 492 bits of data and 18 bits of error
  94.                correcting code.
  95.  
  96.           (3)  The 512 bits frames are then interlaced with an audio
  97.                stream and transmitted over px64 kbps circuits according
  98.                to specification H.261.
  99.  
  100.           When transmitting over the Internet, we will directly consider
  101.           the output of the Huffman encoding. We will not carry the 512
  102.           bits frames, as protection against errors can be obtained by
  103.           other means. Similarly, we will not attempt to multiplex audio
  104.           and video signals in the same packets, as UDP and RTP provide
  105.           a much more efficient way to achieve multiplexing.
  106.  
  107.           Directly transmitting the result of the Huffman encoding over
  108.           an unreliable stream of UDP datagrams would however have very
  109.           poor error resistance characteristics. The H.261 coding is in
  110.           fact organized as a sequence of images, or frames, which are
  111.           themselves organized as a set of Groups of Blocks (GOB). Each
  112.           GOB holds a set of 3 lines of 11 macro blocs (MB). Each MB
  113.  
  114.  
  115.  
  116.  
  117.  
  118.           Turletti, Huitema                                     [Page 2]
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.           Internet draft                     Packetization of H.261
  126.  
  127.  
  128.           carries information on a group of 16x16 pixels: luminance
  129.           information is specified for 4 blocks of 8x8 pixels, while
  130.           chrominance information is only given by two 8x8 "red" and
  131.           "blue" blocks.
  132.  
  133.           This grouping is used to specify informations at each level of
  134.           the hierarchy:
  135.  
  136.           -    At the frame level, one specifies informations such as
  137.                the delay from the previous frame, the image format, and
  138.                various indicators.
  139.  
  140.           -    At the GOB level, one specifies the GOB number and the
  141.                default quantifier that will be used for the MBs.
  142.  
  143.           -    At the MB level, one specifies which blocks are presents
  144.                and which did not change, and optionally a quantifier, as
  145.                well as precisions on the codings such as distance
  146.                vectors.
  147.  
  148.           The result of this structure is that one need to receive the
  149.           informations present in the frame header to decode the GOBs,
  150.           as well as the informations present in the GOB header to
  151.           decode the MBs. Without precautions, this would mean that one
  152.           has to receive all the packets that carry an image in order to
  153.           properly decode its components. In fact, the experience as
  154.           shown that:
  155.  
  156.           (1)  It would be unrealistic to carry an image on a single
  157.                packet: video images can sometime be very large.
  158.  
  159.           (2)  GOB informations would most often be correctly sized to
  160.                fit in a packet. In fact, several GOBs can often be
  161.                grouped in a packet.
  162.  
  163.           Once we have take the decision to correlate GOB
  164.           synchronization and packetization, a number of decisions
  165.           remain to be taken, due to the following conditions:
  166.  
  167.           (1)  The algorithm should be easy to implement when
  168.                packetizing the output stream of an hardware codec.
  169.  
  170.           (2)  The algorithm should not induce rendition delays -- we
  171.                should not have to wait for a following packet to display
  172.                an image.
  173.  
  174.  
  175.  
  176.  
  177.  
  178.           Turletti, Huitema                                     [Page 3]
  179.  
  180.  
  181.  
  182.  
  183.  
  184.           Internet draft                     Packetization of H.261
  185.  
  186.  
  187.           (3)  The algorithm should allow for efficient
  188.                resynchronization in case of packet losses.
  189.  
  190.           (4)  It should be easy to depacketize the data stream and
  191.                direct it to an hardware codec's input.
  192.  
  193.           (5)  When the hardware decoder operates at a fixed bit rate,
  194.                one should be able to maintain synchronization, e.g. by
  195.                adding padding bits when the packet arrival rate is
  196.                slower than the bit rate.
  197.  
  198.           The H.261 Huffmans encoding includes a special "GOB start"
  199.           pattern, composed of 15 zeroes followed by a single 1, that
  200.           cannot be imitated by any other code words. That patterns mark
  201.           the separation between two GOBs, and is in fact used as an
  202.           indicator that the current GOB is terminated. The encoding
  203.           also include a stuffing pattern, composed of seven zeroes
  204.           followed by four ones; that stuffing pattern can only be
  205.           entered between the encoding of MBs, or just before the GOB
  206.           separator.
  207.  
  208.           The first conclusion of the analysis is that the packets
  209.           should contain all the GOB data, including the "GOB start"
  210.           pattern that separate the current block from its follower. In
  211.           fact, as this pattern is well known, we could as well use a
  212.           single bit in the data header to indicate it's presence.
  213.  
  214.           Not encoding the GOB-start pattern has two advantages:
  215.  
  216.           (1)  It reduces the number of bits in the packets, and avoids
  217.                the possibility of splitting packets in the middle of a
  218.                GOB separator.
  219.  
  220.           (2)  It authorize gateways to hardware decoders to insert the
  221.                stuffing pattern in front of the GOB, in order to meet
  222.                the fixed bit rate requirement.
  223.  
  224.           Another problem posed by the specificities of the H.261
  225.           compression is that the GOB data have no particular reason to
  226.           fit in an integer number of octets.  The data header will thus
  227.           contain two three bits integers, EBIT and SBIT:
  228.  
  229.           SBIT indicates the number of bits that should be ignored in
  230.                the first (start) data octet.
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.           Turletti, Huitema                                     [Page 4]
  238.  
  239.  
  240.  
  241.  
  242.  
  243.           Internet draft                     Packetization of H.261
  244.  
  245.  
  246.           EBIT indicates the number of bits that should be ignored in
  247.                the last (end) data octet.
  248.  
  249.           Although only the EBIT counter would really be needed for
  250.           software coders, the SBIT counter was inserted to ease the
  251.           packetization of hardware coders output.  An sample
  252.           packetization procedure is found in annex A.
  253.  
  254.           At the receiving sites, the GOB synchronization can be used in
  255.           conjunction with the synchronization service of the RTP
  256.           protocol. In case of losses, the decoders could become
  257.           desynchronized. The "S" bit of the RTP header will be set to
  258.           indicate that the packet includes the beginning of the
  259.           encoding of a GOB, i.e. the quantifier common to all macro
  260.           blocks. The receiver will detect losses by looking at the RTP
  261.           sequence numbers. In case of losses, it will ignore all
  262.           packets whose "S" bit is null. Once an S bit packet has been
  263.           received, it will prepend the GOB start code to that packet,
  264.           and resume decoding.
  265.  
  266.           A example packetization program is given in Appendix A.
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.           Turletti, Huitema                                     [Page 5]
  297.  
  298.  
  299.  
  300.  
  301.  
  302.           Internet draft                     Packetization of H.261
  303.  
  304.  
  305.           4.  Usage of RTP
  306.  
  307.           The H.261 informations are carried as data within the RTP
  308.           protocol, using the following informations:
  309.  
  310.                   _____________________________________________
  311.                  | Ver       |   Protocol version (1).        |
  312.                  |___________|________________________________|
  313.                  | Flow      |   Identifies one particular    |
  314.                  |           |   video stream.                |
  315.                  |___________|________________________________|
  316.                  | Content   |   H.261 encoded video (31).    |
  317.                  |___________|________________________________|
  318.                  | Sequence  |   Identifies the packet within |
  319.                  | number    |   a stream                     |
  320.                  |___________|________________________________|
  321.                  | Sync      |   Set if the packet is         |
  322.                  |           |   synchronized on an image or  |
  323.                  |           |   on a group of blocks.        |
  324.                  |___________|________________________________|
  325.                  | Timestamp |   The date at which the        |
  326.                  |           |   image was grabbed.           |
  327.                  |___________|________________________________|
  328.  
  329.  
  330.           The very definition of this settings implies that the
  331.           beginning of an image shall always be synchronized with a
  332.           packet. The RTP sequence number can be used to detect missing
  333.           packets. In this case, one shall ignore all incomings packets
  334.           until the next synchronization mark is received. The H.261
  335.           data will follow the RTP options, as in:
  336.  
  337.             0                   1                   2                   3
  338.             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  339.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  340.            |Ver| flow      |F|S|  content  | sequence number               |
  341.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  342.            | timestamp (seconds)           | timestamp (fraction)          |
  343.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  344.            .                                                               .
  345.            .                    RTP options (optional)                     .
  346.            .                                                               .
  347.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  348.            |        H.261  options         |         H.261 stream...       |
  349.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  350.  
  351.  
  352.  
  353.  
  354.  
  355.           Turletti, Huitema                                     [Page 6]
  356.  
  357.  
  358.  
  359.  
  360.  
  361.           Internet draft                     Packetization of H.261
  362.  
  363.  
  364.           The H.261 options field is defined as following:
  365.  
  366.             0                   1
  367.             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  368.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  369.            |S|SBIT |E|EBIT |C|I|V|0|  FMT  |
  370.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  371.  
  372.              _______________________________________________________
  373.             | S (1 bit)     |   Start of GOB. Set if               |
  374.             |               |   the packet is a start of GOB.      |
  375.             |_______________|______________________________________|
  376.             | SBIT (3 bits) |   Start bit position                 |
  377.             |               |   number of bits that should         |
  378.             |               |   be ignored in the first            |
  379.             |               |   (start) data octet.                |
  380.             |_______________|______________________________________|
  381.             | E (1 bit)     |   End of GOB. Set if                 |
  382.             |               |   the packet is an end of GOB.       |
  383.             |_______________|______________________________________|
  384.             | EBIT (3 bits) |   End bit position                   |
  385.             |               |   number of bits that should         |
  386.             |               |   be ignored in the last             |
  387.  
  388.             |               |   (end) data octet.                  |
  389.             |_______________|______________________________________|
  390.             | C (1 bit)     |   Color flag. Set if                 |
  391.             |               |   color is encoded.                  |
  392.             |_______________|______________________________________|
  393.             | I (1 bit)     |   Full Intra Image flag.             |
  394.             |               |   Set if it is the first packet      |
  395.             |               |   of a full intra image.             |
  396.             |_______________|______________________________________|
  397.             | V (1 bit)     |   movement Vector flag.              |
  398.             |               |   Set if movement vectors            |
  399.             |               |   are encoded.                       |
  400.             |_______________|______________________________________|
  401.             | FMT (4 bits)  |   Image format:                      |
  402.             |               |   QCIF, CIF or number of CIF in SCIF.|
  403.             |_______________|______________________________________|
  404.  
  405.  
  406.           The image format (4 bits) is defined as following:
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.           Turletti, Huitema                                     [Page 7]
  416.  
  417.  
  418.  
  419.  
  420.  
  421.           Internet draft                     Packetization of H.261
  422.  
  423.  
  424.                           _____________________________
  425.                          | QCIF               |   0000|
  426.                          |____________________|_______|
  427.                          | CIF                |   0001|
  428.                          |____________________|_______|
  429.                          | SCIF 0             |       |
  430.                          | upper left corner  |   0100|
  431.                          | CIF in SCIF image  |       |
  432.                          |____________________|_______|
  433.                          | SCIF 1             |       |
  434.                          | upper right corner |   0101|
  435.                          | CIF in SCIF image  |       |
  436.                          |____________________|_______|
  437.                          | SCIF 2             |       |
  438.                          | lower left corner  |   0110|
  439.                          | CIF in SCIF image  |       |
  440.                          |____________________|_______|
  441.                          | SCIF 3             |       |
  442.                          | lower right corner |   0111|
  443.                          | CIF in SCIF image  |       |
  444.                          |____________________|_______|
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.           Turletti, Huitema                                     [Page 8]
  475.  
  476.  
  477.  
  478.  
  479.  
  480.           Internet draft                     Packetization of H.261
  481.  
  482.  
  483.           5.  Usage of RTP parameters
  484.  
  485.           When sending or receiving H.261 streams through the RTP
  486.           protocol, the stations should be ready to:
  487.  
  488.           (1)  process or ignore all generic RTP parameters,
  489.  
  490.           (2)  send or receive H.261 specific "Reverse Application Data"
  491.                parameters, to request a video resynchronization.
  492.  
  493.           This memo describes two "RAD" item types, "Full Intra Request"
  494.           and "Negative Acknowledge".
  495.  
  496.           5.1.  Controlling the reverse flow
  497.  
  498.           Support of the reverse application data by the H.261 sender is
  499.           optional; in particular, early experiments have shown that the
  500.           usage of this feature could have very negative effects when
  501.           the number of recipients is very large.
  502.  
  503.           Recipients learn the return address where RAD informations may
  504.           be sent from the Content description (CDESC) item, which may
  505.           be included as an RTP option in any of the video packets. The
  506.           CDESC item includes a Return port number value. A value of
  507.           zero indicates that no reverse control information should be
  508.           returned.
  509.  
  510.           A recipient shall never send a RAD item if it has not yet
  511.           received a CDESC item from the source, or if the port number
  512.           received in the last CDESC item was null.
  513.  
  514.           Emitters should identify themselves by sending CDESC items at
  515.           regular intervals.
  516.  
  517.           5.2.  Full Intra Request
  518.  
  519.           The "Full Intra Request" items are identified by the item Type
  520.           "FIR" (0).
  521.  
  522.             0                   1                   2                   3
  523.             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  524.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  525.            |F|    RAD      |  length = 1   |   Type        | Z |   Flow    |
  526.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.           Turletti, Huitema                                     [Page 9]
  534.  
  535.  
  536.  
  537.  
  538.  
  539.           Internet draft                     Packetization of H.261
  540.  
  541.  
  542.           These packets indicate that a recipient has lost all video
  543.           synchronization, and request the emitter to send the next
  544.           image in "Intra" coding mode, i.e.  without using differential
  545.           coding. The various fields are defined as follow:
  546.  
  547.                  ________________________________________________
  548.                 | F      |   Last option bit, as defined by RTP.|
  549.                 |________|______________________________________|
  550.                 | RAD    |   RAD option type (65)               |
  551.                 |________|______________________________________|
  552.                 | Length |   One 32 bits word.                  |
  553.                 |________|______________________________________|
  554.                 | Type   |   FIR (0).                           |
  555.                 |________|______________________________________|
  556.                 |  Z     |   Must be zero                       |
  557.                 |________|______________________________________|
  558.                 | Flow   |   The flow id of the incoming packets|
  559.                 |________|______________________________________|
  560.  
  561.  
  562.           5.3.  Negative Acknowledge
  563.  
  564.  
  565.           Packet losses are detected using the RTP sequence number.
  566.           After a packet loss, the receiver will resynchronize on the
  567.           next GOB. However, as H.261 uses differential encoding, parts
  568.           of the images may remain blurred for a rather long time.
  569.  
  570.           As all GOB belonging to a given video image carry the same
  571.           time stamp, the receiver can determine a list of GOBs which
  572.           were effectively received for that time stamp, and thus
  573.           identify the "missing blocks". Requesting a specific
  574.           reinitialization of these missing blocks is more efficient
  575.           than requesting a complete reinitialization of the image
  576.           through the "Full Intra Request" item.
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.           Turletti, Huitema                                    [Page 10]
  594.  
  595.  
  596.  
  597.  
  598.  
  599.           Internet draft                     Packetization of H.261
  600.  
  601.  
  602.           The format of the video-nack option is as follow:
  603.  
  604.             0                   1                   2                   3
  605.             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  606.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  607.            |F|    RAD      |  length = 3   |   Type        | Z |   Flow    |
  608.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  609.            |     FGOBL     |     LGOBL     |    MBZ                |  FMT  |
  610.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  611.            | timestamp (seconds)           | timestamp (fraction)          |
  612.            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  613.  
  614.           The different fields have the following values:
  615.  
  616.              ________________________________________________________
  617.             | F             |   Last option bit, as defined by RTP. |
  618.             |_______________|_______________________________________|
  619.             | RAD           |   RAD option type (65)                |
  620.             | -             |                                       |
  621.             | Length        |   Three 32 bits word.                 |
  622.             |_______________|_______________________________________|
  623.             | Type          |   NACK (1).                           |
  624.             |_______________|_______________________________________|
  625.             | MBZ           |   Must be zero                        |
  626.             |_______________|_______________________________________|
  627.             | Flow          |   The flow id of the incoming packets |
  628.             |_______________|_______________________________________|
  629.             | FGOBL         |   First GOB Lost:                     |
  630.             |               |  Identifies the first GOB lost number.|
  631.             |_______________|_______________________________________|
  632.             | LGOBL         |   Last GOB Lost:                      |
  633.             |               |   Identifies the last GOB lost number.|
  634.             |_______________|_______________________________________|
  635.             | MBZ           |   Must be zero                        |
  636.             |_______________|_______________________________________|
  637.             | FMT           |   Repeat the format indicator of the  |
  638.             |               |   received image, including the number|
  639.             |               |   of the SCIF subimage if present.    |
  640.             |_______________|_______________________________________|
  641.             | Timestamp     |   The RTP timestamp of the            |
  642.             | original image|                                       |
  643.             |_______________|_______________________________________|
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.           Turletti, Huitema                                    [Page 11]
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.           Internet draft                     Packetization of H.261
  660.  
  661.  
  662.           6.  References
  663.  
  664.           [1]  Video codec for audiovisual services at p x 64 kbit/s
  665.                CCITT Recommendation H.261.
  666.  
  667.           [2]  Thierry Turletti. H.261 software codec for
  668.                videoconferencing over the Internet INRIA Research Report
  669.                no 1834
  670.  
  671.  
  672.           [3]  Henning Schulzrinne A Transport Protocol for Real-Time
  673.                Applications INTERNET-DRAFT, December 15, 1992.
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.           Turletti, Huitema                                    [Page 12]
  714.  
  715.  
  716.  
  717.  
  718.  
  719.           Internet draft                     Packetization of H.261
  720.  
  721.  
  722.           Appendix A
  723.  
  724.           The following code can be used to packetize the output of an
  725.           H.261 codec:
  726.  
  727.           #include <stdio.h>
  728.  
  729.           #define BUFFER_MAX 512
  730.  
  731.           int right[] = {
  732.              8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  733.              2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
  734.              1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  735.              1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  736.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  737.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  738.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  739.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  740.  
  741.           int left[] = {
  742.              8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  743.              5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  744.              6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  745.              5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  746.              7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  747.              5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  748.              6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
  749.              5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0};
  750.  
  751.           h261_sync(F)
  752.              FILE *F;
  753.           {
  754.              int  i, ebit, sbit, start_of_group, end_of_group,
  755.                    c, nz;
  756.              unsigned char buf[BUFFER_MAX];
  757.              int *left, *right;
  758.  
  759.              i = 0;
  760.              ebit = 0;
  761.              sbit = 0;
  762.              start_of_group = 1;
  763.              nz = 0;
  764.              while (c = getc(F)) {
  765.                 buf[i++] = c;
  766.                 if (c == 0) {
  767.  
  768.  
  769.  
  770.  
  771.  
  772.           Turletti, Huitema                                    [Page 13]
  773.  
  774.  
  775.  
  776.  
  777.  
  778.           Internet draft                     Packetization of H.261
  779.  
  780.  
  781.                    nz += 8;
  782.                 } else {
  783.                    nz += right[c];
  784.                    end_of_group = 1;
  785.                    if (nz >= 15) {
  786.                       if (right[c] == 7) {
  787.                          ebit = 0;
  788.                          send_message(buf, i - 2, sbit, ebit,
  789.                             end_of_group, start_of_group);
  790.                          sbit = 0;
  791.                          i = 0;
  792.                       } else {
  793.                          ebit = 7 - right[c];
  794.                          send_message(buf, i - 2, sbit, ebit,
  795.                             end_of_group, start_of_group);
  796.                          i = 0;
  797.                          buf[i++] = c;
  798.                          sbit = right[c] + 1;
  799.                       }
  800.                       start_of_group = 1;
  801.                    } else {
  802.                       nz = left[c];
  803.                       if (i >= BUFFER_MAX) {
  804.                          ebit = 0;
  805.                          end_of_group = 0;
  806.                          send_message(buf, i - 2, sbit, ebit,
  807.                             end_of_group, start_of_group);
  808.                          buf[0] = buf[i - 2];
  809.                          buf[1] = buf[i - 1];
  810.                          i = 2;
  811.                          sbit = 0;
  812.                          start_of_group = 0;
  813.                       }
  814.                    }
  815.                 }
  816.              }
  817.           }
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.           Turletti, Huitema                                    [Page 14]
  833.  
  834.  
  835.  
  836.  
  837.  
  838.           Internet draft                     Packetization of H.261
  839.  
  840.  
  841.           Table of Contents
  842.  
  843.  
  844.           1 Status of this Memo ...................................    1
  845.           2 Purpose of this document ..............................    2
  846.           3 Structure of the packet stream ........................    2
  847.           4 Usage of RTP ..........................................    6
  848.           5 Usage of RTP parameters ...............................    9
  849.           5.1 Controlling the reverse flow ........................    9
  850.           5.2 Full Intra Request ..................................    9
  851.           5.3 Negative Acknowledge ................................   10
  852.           6 References ............................................   12
  853.            Appendix A .............................................   13
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.           Turletti, Huitema                                    [Page 15]
  892.  
  893.  
  894.  
  895.  
  896.